<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>构造函数方法创建对象</title>
</head>
<body>
    <script>
        //构造函数方法创建对象
        function student(name,age,address){
            this.name = name;
            this.age = age;
            this.address = address;
            this.print = print;
        };
        //使用原型方法声明(prototype方法)
        //funtionname.prototype.prototypename = value
        student.prototype.print = function(){
                console.log("姓名:"+this.name);
                console.log("年纪:"+this.age);
                console.log("地址:"+this.address);
            }
        var stu1 = new student("zhangsan",18,"北京市");
        stu1.print();


        
        //使用构造方法(this方法)
        function student(name,age,address){
            this.name = name;
            this.age = age;
            this.address = address;
            this.print = print;
        };
        function print(){
                console.log("姓名:"+this.name);
                console.log("年纪:"+this.age);
                console.log("地址:"+this.address);
        }
        var stu2 = new student("lisi",16,"台湾");
        stu2.print();
    </script>
</body>
</html>